#  CONFIGURATION: edit this as you need
# Set this to your Qtopia source directory
QTOPIA_DIR=~/z6/qpe/qtopia-opensource-src-4.3.2-snapshot-20080917
LRELEASE=lrelease
LOCALE=uk_UA
# Normally, you won't need to edit anything below

TRANSLATIONS=$(shell find src -name '*.ts')
BIN_TRANSLATIONS=$(subst .ts,.qm,$(TRANSLATIONS))
I18DIR=$(shell pwd)
DIST_FILENAME=qtopia-i18n-$(LOCALE)-$(shell date '+%F').tar.gz

default: info

apply: clean
	@echo "Copying translation files to Qtopia source tree..."
	@cp -Rfs src/* $(QTOPIA_DIR)

fetch:
	@mkdir -p src
	@mkdir -p src/i18n
	@(cd $(QTOPIA_DIR) && find -name "*-$(LOCALE).ts" -exec cp --parents \{\} $(I18DIR)/src \;)
	@cp -R $(QTOPIA_DIR)/i18n/$(LOCALE) src/i18n

$(BIN_TRANSLATIONS): %.qm: %.ts
	@$(LRELEASE) -verbose $<

compile: $(BIN_TRANSLATIONS)

clean:
	@echo "Removing .qm files..."
	@echo "...from image"
	@rm -f image/*.qm
	@rm -f image/.directory
	@echo "...from sources"
	@rm -f $(BIN_TRANSLATIONS)

image: compile
	@echo "Copying .qm files to image/"
	@mkdir -p image
	@cp -f src/i18n/$(LOCALE)/.directory image/
	@cp -f $(BIN_TRANSLATIONS) image/
	@for FILE in image/* ; do NEWFILE=`echo $$FILE | sed "s/-$(LOCALE)//g"` ; [ z$$FILE != z$$NEWFILE ] && mv -f "$$FILE" "$$NEWFILE" ; done

tar-image: image
	@echo "Building archive $(DIST_FILENAME)"
	@tar "--transform=s,^image,i18n/$(LOCALE),x" "--exclude=.svn" --show-transformed -cvzf $(DIST_FILENAME) image

info:
	@echo "Qtopia $(LOCALE) i18n pack installer"
	@echo "Please, check that your Qtopia source directory is \`$(QTOPIA_DIR)'"
	@echo
	@echo "Usage:"
	@echo "* make fetch - copy translation data from source tree"
	@echo "* make apply - copy translation data into source tree"
	@echo "* make image - compile translation files into image/"
	@echo "* make clean - remove all .qm files"
	@echo
	@echo "$(shell echo $(TRANSLATIONS) | wc -w) translations found."

.PHONY: default fetch apply info compile image tar-image
